package com.tuniu.agents.util;

import org.springframework.ai.chat.model.ChatResponse;

/**
 * ChatResponse Utility Class
 */
public class ChatResponseUtils {

    /**
     * Get the name of the first tool
     *
     * @param chatResponse The response
     * @return toolName
     */
    public static String getFirstToolName(ChatResponse chatResponse) {
        return chatResponse.getResults().get(0).getMetadata().get("toolName");
    }

    /**
     * Get the first text output
     *
     * @param chatResponse The response
     * @return If it's a tool, return the tool's response; if it's a model output, return natural language
     */
    public static String getFirstTextMessage(ChatResponse chatResponse) {
        return chatResponse.getResults().get(0).getOutput().getText() == null ? "" : chatResponse.getResults().get(0).getOutput().getText();
    }

    /**
     * Get the reasoning content
     * @param chatResponse The response
     * @return Reasoning content as a string
     */
    public static String getThinkTextMessage(ChatResponse chatResponse) {
        return chatResponse.getResults().get(0).getOutput().getMetadata().get("reasoningContent") == null ?
                "" : chatResponse.getResults().get(0).getOutput().getMetadata().get("reasoningContent").toString();
    }
}
